<?php


/**
 * 系统模板配置[前端]
 * Enter description here ...
 * @author Admin
 *
 */
class TplAction extends CommonAction{
	
	/**
	 * 模板配置首页
	 * Enter description here ...
	 */
	public function index() {
		$configpath = ROOT_PATH.'/app/Conf/';   //前台配置文件
		$configpath = realpath($configpath);
		$configcontent = file_get_contents($configpath);
		
		preg_match('/\'DEFAULT_THEME\'=>\'(.*?)\',/iUs',$configcontent,$reg);
		if(empty($reg[1])){
			$currtpl = 'default';
		}else{
			$currtpl = $reg[1];
		}
		

		$tplpath = ROOT_PATH.'/app/Tpl/';    //前台页面模板目录
		$tplpath = realpath($tplpath);
		$arr = scandir($tplpath);   //前台模板目录
		
		$this->assign('currtpl',$currtpl);
		$this->assign('arr',$arr);
		
		$this->display();
	}

	
	/**
	 * 模板配置设置
	 * Enter description here ...
	 */
	public function save(){
		$data = Init_GP(array('tpl'));
		
		$configpath = ROOT_PATH.'/app/Conf/config.php';
		$configpath = realpath($configpath);
		$configcontent = file_get_contents($configpath);
		$configcontent = preg_replace('/\'DEFAULT_THEME\'=>\'(.*?)\',/iUs',"'DEFAULT_THEME'=>'{$data['tpl']}',",$configcontent);
		
		@file_put_contents($configpath, $configcontent);   //前端模板设置写入到缓存文件
		
		$this->success('更改模板成功，请清空缓存！');
	}
	
	
}

?>